package com.baizhi.service.impl;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.dao.BannerDao;
import com.baizhi.entity.Banner;
import com.baizhi.service.BannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerDao bannerDao;

    //查询所有轮播图  分页查询
//    @LogAnnotation(value = "查询轮播图的信息",type = "select")
    @Override
    public Map listBanner(int page, int limit) {
        int start=(page-1)*limit;
        List<Banner> bannerList = bannerDao.listBanner(start, limit);
        int count=bannerDao.countBanner();
        Map map=new HashMap();
        map.put("data",bannerList);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");
//        log.debug("查询所有轮播图");
        return map;
    }

    //添加轮播图
    @LogAnnotation(value = "添加轮播图的信息",type = "insert")
    @Override
    public Map insertBanner(Banner banner) {
        int i = bannerDao.insertBanner(banner);
        Map map=new HashMap();
        if(i>0){
            map.put("insertBanner","添加成功！");
        }else{
            map.put("insertBanner","添加失败！");
        }
        return map;
    }

    //查询轮播图对象
    @Override
    public Banner selectBannerById(Integer id) {
        return bannerDao.selectBannerById(id);
    }

    //修改轮播图
    @Override
    public Map updateBanner(Banner banner) {
        int i = bannerDao.updateBanner(banner);
        Map map=new HashMap();
        if(i>0){
            map.put("updateBanner","修改成功！");
        }else{
            map.put("updateBanner","修改失败！");
        }
        return map;
    }

    //批量删除轮播图
    @Override
    public Map multiDelete(Integer[] ids) {
        int i = bannerDao.multiDelete(ids);
        Map map=new HashMap();
        if(i>0){
            map.put("multiDelete","删除成功！");
        }else{
            map.put("multiDelete","删除失败！");
        }
        return map;
    }
}
